Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

d3plus-viz

Package Overview
Dependencies
Maintainers
0
Versions
210
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3plus-viz

Abstract ES6 class that drives d3plus visualizations.

  • 1.3.11
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

d3plus-viz

Abstract ES6 class that drives d3plus visualizations.

Installing

If using npm, npm install d3plus-viz. Otherwise, you can download the latest release from GitHub or load from a CDN.

import modules from "d3plus-viz";

d3plus-viz can be loaded as a standalone library or bundled as part of D3plus. ES modules, AMD, CommonJS, and vanilla environments are supported. In vanilla, a d3plus global is exported:

<script src="https://cdn.jsdelivr.net/npm/d3plus-viz@1"></script>
<script>
  console.log(d3plus);
</script>

Examples

Live examples can be found on d3plus.org, which includes a collection of example visualizations using d3plus-react. These examples are powered by the d3plus-storybook repo, and PRs are always welcome. :beers:

API Reference

  • Viz
  • isData - Adds the provided value to the internal queue to be loaded, if necessary. This is used internally in new d3plus visualizations that fold in additional data sources, like the nodes and links of Network or the topojson of Geomap.
  • dataConcat - Reduce and concat all the elements included in arrayOfArrays if they are arrays. If it is a JSON object try to concat the array under given key data. If the key doesn't exists in object item, a warning message is lauched to the console. You need to implement DataFormat callback to concat the arrays manually.
  • dataFold - Given a JSON object where the data values and headers have been split into separate key lookups, this function will combine the data values with the headers and returns one large array of objects.
  • isData - Returns true/false whether the argument provided to the function should be loaded using an internal XHR request. Valid data can either be a string URL or an Object with "url" and "headers" keys.
  • dataLoad - Loads data from a filepath or URL, converts it to a valid JSON object, and returns it to a callback function.
  • defaultPadding - Default padding logic that will return false if the screen is less than 600 pixels wide.
  • listify - Turns an array of values into a list string.
  • _thresholdFunction - Applies the threshold algorithm according to the type of chart used.

Viz <>

This is a global class, and extends all of the methods and functionality of BaseClass.

# new Viz()

Creates an x/y plot based on an array of data. If data is specified, immediately draws the tree map based on the specified array and returns the current class instance. If data is not specified on instantiation, it can be passed/updated after instantiation using the data method. See this example for help getting started using the treemap generator.

# Viz.render([callback]) <>

Draws the visualization given the specified configuration.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.active([value]) <>

If value is specified, sets the active method to the specified function and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.aggs([value]) <>

If value is specified, sets the aggregation method for each key in the object and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.ariaHidden([value]) <>

Sets the "aria-hidden" attribute of the containing SVG element. The default value is "false", but it you need to hide the SVG from screen readers set this property to "true".

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.attribution(value) <>

Sets text to be shown positioned absolute on top of the visualization in the bottom-right corner. This is most often used in Geomaps to display the copyright of map tiles. The text is rendered as HTML, so any valid HTML string will render as expected (eg. anchor links work).

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.attributionStyle([value]) <>

If value is specified, sets the config method for the back button and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.backConfig([value]) <>

If value is specified, sets the config method for the back button and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.cache([value]) <>

Enables a lru cache that stores up to 5 previously loaded files/URLs. Helpful when constantly writing over the data array with a URL in the render function of a react component.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.color([value]) <>

Defines the main color to be used for each data point in a visualization. Can be either an accessor function or a string key to reference in each data point. If a color value is returned, it will be used as is. If a string is returned, a unique color will be assigned based on the string.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.colorScale([value]) <>

Defines the value to be used for a color scale. Can be either an accessor function or a string key to reference in each data point.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.colorScaleConfig([value]) <>

A pass-through to the config method of ColorScale.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.colorScalePadding([value]) <>

Tells the colorScale whether or not to use the internal padding defined by the visualization in it's positioning. For example, d3plus-plot will add padding on the left so that the colorScale appears centered above the x-axis. By default, this padding is only applied on screens larger than 600 pixels wide.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.colorScalePosition([value]) <>

Defines which side of the visualization to anchor the color scale. Acceptable values are "top", "bottom", "left", "right", and false. A false value will cause the color scale to not be displayed, but will still color shapes based on the scale.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.colorScaleMaxSize([value]) <>

Sets the maximum pixel size for drawing the color scale: width for horizontal scales and height for vertical scales.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.data(data, [formatter]) <>

Sets the primary data array to be used when drawing the visualization. The value passed should be an Array of objects or a String representing a filepath or URL to be loaded. The following filetypes are supported: csv, tsv, txt, and json.

If your data URL needs specific headers to be set, an Object with "url" and "headers" keys may also be passed.

Additionally, a custom formatting function can be passed as a second argument to this method. This custom function will be passed the data that has been loaded, as long as there are no errors. This function should return the final array of obejcts to be used as the primary data array. For example, some JSON APIs return the headers split from the data values to save bandwidth. These would need be joined using a custom formatter.

If you would like to specify certain configuration options based on the yet-to-be-loaded data, you can also return a full config object from the data formatter (including the new data array as a key in the object).

If data is not specified, this method returns the current primary data array, which defaults to an empty array ([]);

This is a static method of Viz, and is chainable with other methods of this Class.

ParamTypeDescription
dataArray | String= []
[formatter]function

# Viz.dataCutoff([value]) <>

If the number of visible data points exceeds this number, the default hover behavior will be disabled (helpful for very large visualizations bogging down the DOM with opacity updates).

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.depth([value]) <>

If value is specified, sets the depth to the specified number and returns the current class instance. The value should correspond with an index in the groupBy array.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.detectResize(value) <>

If the width and/or height of a Viz is not user-defined, it is determined by the size of it's parent element. When this method is set to true, the Viz will listen for the window.onresize event and adjust it's dimensions accordingly.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.detectResizeDelay(value) <>

When resizing the browser window, this is the millisecond delay to trigger the resize event.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.detectVisible(value) <>

Toggles whether or not the Viz should try to detect if it visible in the current viewport. When this method is set to true, the Viz will only be rendered when it has entered the viewport either through scrolling or if it's display or visibility is changed.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.detectVisibleInterval(value) <>

The interval, in milliseconds, for checking if the visualization is visible on the page.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.discrete([value]) <>

If value is specified, sets the discrete accessor to the specified method name (usually an axis) and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.downloadButton([value]) <>

Shows a button that allows for downloading the current visualization.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.downloadConfig([value]) <>

Sets specific options of the saveElement function used when downloading the visualization.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.downloadPosition([value]) <>

Defines which control group to add the download button into.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.duration([ms]) <>

If ms is specified, sets the animation duration to the specified number and returns the current class instance. If ms is not specified, returns the current animation duration.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.filter([value]) <>

If value is specified, sets the filter to the specified function and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.groupBy([value]) <>

If value is specified, sets the group accessor(s) to the specified string, function, or array of values and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

function value(d) {
  return d.id;
}

# Viz.height([value]) <>

If value is specified, sets the overall height to the specified number and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.hiddenColor([value]) <>

Defines the color used for legend shapes when the corresponding grouping is hidden from display (by clicking on the legend).

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.hiddenOpacity([value]) <>

Defines the opacity used for legend labels when the corresponding grouping is hidden from display (by clicking on the legend).

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.hover([value]) <>

If value is specified, sets the hover method to the specified function and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.label([value]) <>

If value is specified, sets the label accessor to the specified function or string and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.legend([value]) <>

If value is specified, toggles the legend based on the specified boolean and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.legendConfig([value]) <>

If value is specified, the object is passed to the legend's config method.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.legendFilterInvert([value]) <>

Defines the click functionality of categorical legend squares. When set to false, clicking will hide that category and shift+clicking will solo that category. When set to true, clicking with solo that category and shift+clicking will hide that category.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.legendPadding([value]) <>

Tells the legend whether or not to use the internal padding defined by the visualization in it's positioning. For example, d3plus-plot will add padding on the left so that the legend appears centered underneath the x-axis. By default, this padding is only applied on screens larger than 600 pixels wide.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.legendPosition([value]) <>

Defines which side of the visualization to anchor the legend. Expected values are "top", "bottom", "left", and "right".

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.legendSort(value) <>

A JavaScript sort comparator function used to sort the legend.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.legendTooltip([value]) <>

If value is specified, sets the config method for the legend tooltip and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.loadingHTML([value]) <>

Sets the inner HTML of the status message that is displayed when loading AJAX requests and displaying errors. Must be a valid HTML string or a function that, when passed this Viz instance, returns a valid HTML string.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.loadingMessage([value]) <>

Toggles the visibility of the status message that is displayed when loading AJAX requests and displaying errors.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.messageMask([value]) <>

Sets the color of the mask used underneath the status message that is displayed when loading AJAX requests and displaying errors. Additionally, false will turn off the mask completely.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.messageStyle([value]) <>

Defines the CSS style properties for the status message that is displayed when loading AJAX requests and displaying errors.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.noDataHTML([value]) <>

Sets the inner HTML of the status message that is displayed when no data is supplied to the visualization. Must be a valid HTML string or a function that, when passed this Viz instance, returns a valid HTML string.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.noDataMessage([value]) <>

Toggles the visibility of the status message that is displayed when no data is supplied to the visualization.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.resizeContainer(selector) <>

If using resize detection, this method allow a custom override of the element to which the resize detection function gets attached.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.scrollContainer(selector) <>

If using scroll or visibility detection, this method allow a custom override of the element to which the scroll detection function gets attached.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.select([selector]) <>

If selector is specified, sets the SVG container element to the specified d3 selector or DOM element and returns the current class instance. If selector is not specified, returns the current SVG container element, which is undefined by default.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.shape([value]) <>

If value is specified, sets the shape accessor to the specified function or number and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.shapeConfig([value]) <>

If value is specified, sets the config method for each shape and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.subtitle([value]) <>

If value is specified, sets the subtitle accessor to the specified function or string and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.subtitleConfig([value]) <>

If value is specified, sets the config method for the subtitle and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.subtitlePadding([value]) <>

Tells the subtitle whether or not to use the internal padding defined by the visualization in it's positioning. For example, d3plus-plot will add padding on the left so that the subtitle appears centered above the x-axis. By default, this padding is only applied on screens larger than 600 pixels wide.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.svgDesc([value]) <>

If value is specified, sets the description accessor to the specified string and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.svgTitle([value]) <>

If value is specified, sets the title accessor to the specified string and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.threshold([value]) <>

If value is specified, sets the threshold for buckets to the specified function or string, and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.thresholdKey([value]) <>

If value is specified, sets the accesor for the value used in the threshold algorithm, and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.thresholdName([value]) <>

If value is specified, sets the label for the bucket item, and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.time([value]) <>

If value is specified, sets the time accessor to the specified function or string and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.timeFilter([value]) <>

If value is specified, sets the time filter to the specified function and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.timeline([value]) <>

If value is specified, toggles the timeline based on the specified boolean and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.timelineConfig([value]) <>

If value is specified, sets the config method for the timeline and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.timelineDefault([value]) <>

Sets the starting time or range for the timeline. The value provided can either be a single Date/String, or an Array of 2 values representing the min and max.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.timelinePadding([value]) <>

Tells the timeline whether or not to use the internal padding defined by the visualization in it's positioning. For example, d3plus-plot will add padding on the left so that the timeline appears centered underneath the x-axis. By default, this padding is only applied on screens larger than 600 pixels wide.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.title([value]) <>

If value is specified, sets the title accessor to the specified function or string and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.titleConfig([value]) <>

If value is specified, sets the config method for the title and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.titlePadding([value]) <>

Tells the title whether or not to use the internal padding defined by the visualization in it's positioning. For example, d3plus-plot will add padding on the left so that the title appears centered above the x-axis. By default, this padding is only applied on screens larger than 600 pixels wide.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.tooltip([value]) <>

If value is specified, toggles the tooltip based on the specified boolean and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.tooltipConfig([value]) <>

If value is specified, sets the config method for the tooltip and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.total([value]) <>

If value is specified, sets the total accessor to the specified function or string and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.totalConfig([value]) <>

If value is specified, sets the config method for the total and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.totalFormat(value) <>

Formatter function for the value in the total bar.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.totalPadding([value]) <>

Tells the total whether or not to use the internal padding defined by the visualization in it's positioning. For example, d3plus-plot will add padding on the left so that the total appears centered above the x-axis. By default, this padding is only applied on screens larger than 600 pixels wide.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.width([value]) <>

If value is specified, sets the overallwidth to the specified number and returns the current class instance.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.zoom(value) <>

Toggles the ability to zoom/pan the visualization. Certain parameters for zooming are required to be hooked up on a visualization by visualization basis.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.zoomBrushHandleSize(value) <>

The pixel stroke-width of the zoom brush area.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.zoomBrushHandleStyle(value) <>

An object containing CSS key/value pairs that is used to style the outer handle area of the zoom brush. Passing false will remove all default styling.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.zoomBrushSelectionStyle(value) <>

An object containing CSS key/value pairs that is used to style the inner selection area of the zoom brush. Passing false will remove all default styling.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.zoomControlStyle(value) <>

An object containing CSS key/value pairs that is used to style each zoom control button (.zoom-in, .zoom-out, .zoom-reset, and .zoom-brush). Passing false will remove all default styling.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.zoomControlStyleActive(value) <>

An object containing CSS key/value pairs that is used to style each zoom control button when active (.zoom-in, .zoom-out, .zoom-reset, and .zoom-brush). Passing false will remove all default styling.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.zoomControlStyleHover(value) <>

An object containing CSS key/value pairs that is used to style each zoom control button on hover (.zoom-in, .zoom-out, .zoom-reset, and .zoom-brush). Passing false will remove all default styling.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.zoomFactor(value) <>

The multiplier that is used in with the control buttons when zooming in and out.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.zoomMax(value) <>

If value is specified, sets the max zoom scale to the specified number and returns the current class instance. If value is not specified, returns the current max zoom scale.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.zoomPan(value) <>

If value is specified, toggles panning to the specified boolean and returns the current class instance. If value is not specified, returns the current panning value.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.zoomPadding(value) <>

A pixel value to be used to pad all sides of a zoomed area.

This is a static method of Viz, and is chainable with other methods of this Class.

# Viz.zoomScroll([value]) <>

If value is specified, toggles scroll zooming to the specified boolean and returns the current class instance. If value is not specified, returns the current scroll zooming value.

This is a static method of Viz, and is chainable with other methods of this Class.


d3plus.isData(data, [data], data) <>

Adds the provided value to the internal queue to be loaded, if necessary. This is used internally in new d3plus visualizations that fold in additional data sources, like the nodes and links of Network or the topojson of Geomap.

This is a global function.

ParamTypeDescription
dataArray | String | ObjectThe data to be loaded
[data]functionAn optional data formatter/callback
dataStringThe internal Viz method to be modified

d3plus.dataConcat(arrayOfArray, [data]) <>

Reduce and concat all the elements included in arrayOfArrays if they are arrays. If it is a JSON object try to concat the array under given key data. If the key doesn't exists in object item, a warning message is lauched to the console. You need to implement DataFormat callback to concat the arrays manually.

This is a global function.

ParamTypeDefaultDescription
arrayOfArrayArrayArray of elements
[data]String"data"The key used for the flat data array if exists inside of the JSON object.

d3plus.dataFold(json, [data], [headers]) <>

Given a JSON object where the data values and headers have been split into separate key lookups, this function will combine the data values with the headers and returns one large array of objects.

This is a global function.

ParamTypeDefaultDescription
jsonObjectA JSON data Object with data and headers keys.
[data]String"data"The key used for the flat data array inside of the JSON object.
[headers]String"headers"The key used for the flat headers array inside of the JSON object.

d3plus.isData(dataItem) <>

Returns true/false whether the argument provided to the function should be loaded using an internal XHR request. Valid data can either be a string URL or an Object with "url" and "headers" keys.

This is a global function.


d3plus.dataLoad(path, [formatter], [key], [callback]) <>

Loads data from a filepath or URL, converts it to a valid JSON object, and returns it to a callback function.

This is a global function.

ParamTypeDescription
pathArray | StringThe path to the file or url to be loaded. Also support array of paths strings. If an Array of objects is passed, the xhr request logic is skipped.
[formatter]functionAn optional formatter function that is run on the loaded data.
[key]StringThe key in the this context to save the resulting data to.
[callback]functionA function that is called when the final data is loaded. It is passed 2 variables, any error present and the data loaded.

d3plus.defaultPadding() <>

Default padding logic that will return false if the screen is less than 600 pixels wide.

This is a global function.


d3plus.listify() <>

Turns an array of values into a list string.

This is a global function.


d3plus._thresholdFunction(data) <>

Applies the threshold algorithm according to the type of chart used.

This is a global function.


Documentation generated on Thu, 08 Aug 2024 19:56:22 GMT

Keywords

FAQs

Package last updated on 08 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc